﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.Entity;
using MSD.WL.Site.Models;
using System.Web.Security;

namespace MSD.WL.Site.Controllers
{
    
    public class HomeController : Controller
    {
        // GET: Home
        //代表frame主界面
        EMSContext db = new EMSContext();
        [Authorize]
        public ActionResult Index()
        {
            return View();
        }
        [Authorize]
        public ActionResult homePage()
        {
            ViewBag.UserNum = db.User.Count();
            ViewBag.EmployeeNum = db.Employee.Count();
            ViewBag.CustomersNum = db.Customer.Count();
            ViewBag.SEOrder = db.SEOrder.Count();
            ViewBag.SEGather = db.SEGather.Count();
            ViewBag.InvensNum = db.Invens.Count();
            return View();
        }
        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Login(string username,string password,string securitycode)
        {
            if (String.IsNullOrEmpty(username)||String.IsNullOrEmpty(password)||String.IsNullOrEmpty(securitycode))
            {
                ViewBag.Message = "<script type='text/javascript'>Info('输入信息不完整，请重新登录！')</script>";
                
            }
            if (Session["securitycode"].ToString() != securitycode)
            {
                ViewBag.Message = "<script type='text/javascript'>Info('验证码错误，请重新登录！')</script>";
                
            }
            var user = db.User.Where(x => (x.OperatorName == username) && (x.PassWord == password));
            if (!(user.Count() > 0))
            {
                ViewBag.Message = "<script type='text/javascript'>Info('用户不存在或密码错误，请重新登录！')</script>";
                
            }
            else
            {
                FormsAuthentication.RedirectFromLoginPage(username, false);
                return RedirectToAction("Index", "Home");
            }
            return View();
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Logout()
        {
            FormsAuthentication.SignOut();
            return RedirectToAction("Login", "Home");
        }

        [Authorize]
        public ActionResult Top()
        {
            //ViewBag.UserName = "超级管理员";
            ViewBag.AvailableBlance = "8888.0";
            return View();
        }
        [Authorize]
        public ActionResult Left()
        {
            return View();
        }
        [Authorize]
        public ActionResult Right()
        {
            return View();
        }
    }
}